/*
    $Header: /Windows/Shell/ShellExt.root/ShellExt/src/CShTerm.h 1     08-01-05 0:08 Ken $
    $Log: /Windows/Shell/ShellExt.root/ShellExt/src/CShTerm.h $
 * 
 * 1     08-01-05 0:08 Ken
*/


#pragma once
#include "resource.h"       // main symbols

#include <ExDispid.h>

#include "ConsoleEmbWnd.h"
#include "CIShellExtImp.h"

#define SHTERM_MEMU_NUM    1
#define SHTERM_CLASS_NAME TEXT("SHELL_TERM_WINDOW")

//
// CShTerm
class ATL_NO_VTABLE CShTerm
    :public CComObjectRootEx<CComSingleThreadModel>
    ,public CComCoClass<CShTerm, &CLSID_ShTerm>
    ,public IDispatchImpl<IShTerm, &IID_IShTerm, &LIBID_ShellExtLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
    ,public IDeskBand
    ,public IObjectWithSite
    ,public IInputObject
    ,CIShlCntxMenuImp    // IContextMenu
    ,public CIPersistStreamStubImp<&CLSID_ShTerm>    // IPersistStream
   ,public IDispEventImpl<0, CShTerm, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 0>
{
//
// com stubs
public:
DECLARE_REGISTRY_RESOURCEID(IDR_SHTERM)

BEGIN_COM_MAP(CShTerm)
    COM_INTERFACE_ENTRY(IShTerm)
    COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IObjectWithSite)
    COM_INTERFACE_ENTRY(IInputObject)
    COM_INTERFACE_ENTRY(IContextMenu)
    COM_INTERFACE_ENTRY(IPersistStream)

    COM_INTERFACE_ENTRY(IDispatch)

    //    interface defined by IID
    COM_INTERFACE_ENTRY_IID(IID_IDeskBand, IDeskBand)
END_COM_MAP()

BEGIN_CATEGORY_MAP(CShTerm)
//    IMPLEMENTED_CATEGORY(CATID_DeskBand)
    IMPLEMENTED_CATEGORY(CATID_CommBand)
    IMPLEMENTED_CATEGORY(CATID_InfoBand)
END_CATEGORY_MAP()

BEGIN_SINK_MAP(CShTerm)
    SINK_ENTRY_EX(0, DIID_DWebBrowserEvents2, DISPID_NAVIGATECOMPLETE2, OnNavigateComplete2)
END_SINK_MAP()


    DECLARE_PROTECT_FINAL_CONSTRUCT()

    HRESULT FinalConstruct()
    {
        return S_OK;
    }

    void FinalRelease()
    {
    }

//
// constructs
public:
    CShTerm();
    ~CShTerm(){};

// com interface
// IDeskBand: public IDockingWindow: public IOleWindow
public:
    //IDeskBand methods
    STDMETHOD (GetBandInfo) (DWORD, DWORD, DESKBANDINFO*);
    //IDockingWindow methods
    STDMETHOD (ShowDW) (BOOL fShow);
    STDMETHOD (CloseDW) (DWORD dwReserved);
    STDMETHOD (ResizeBorderDW) (LPCRECT prcBorder, IUnknown* punkToolbarSite, BOOL fReserved);
    //IOleWindow methods
    STDMETHOD (GetWindow) (HWND*);
    STDMETHOD (ContextSensitiveHelp) (BOOL);

//IObjectWithSite methods
public:
    STDMETHOD (SetSite) (IUnknown*);
    STDMETHOD (GetSite) (REFIID, LPVOID*);

//IInputObject methods
public:
    STDMETHOD (UIActivateIO) (BOOL, LPMSG);
    STDMETHOD (HasFocusIO) (void);
    STDMETHOD (TranslateAcceleratorIO) (LPMSG);

//
// DWebBrowserEvents2
private:
    void _stdcall OnNavigateComplete2(IDispatch *pDisp, VARIANT *URL);

//
//CIShlCntxMenuImp :public IContextMenu
    BOOL VIsCmdValid(DWORD dwId){return (4>dwId)?TRUE:FALSE;};
    const TCHAR* VGetMenuString(DWORD dwId);
    DWORD VGetCmdNumb(){return 4;};
    BOOL VInvokeCommand(LPCMINVOKECOMMANDINFO pInfo, DWORD dwId);

//
// I create a parent window for CCmdStubWnd,
// for the edit (CCmdStubWnd) control will send notify to parent,
// if explorer is the parent, it will response these notify with "ding ding..."
//
private:
    BOOL RegisterAndCreateWindow(HWND hwndParent);
static
    LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam);

//
// ui message
    LRESULT OnCommand(HWND hWnd,  WPARAM wParam, LPARAM lParam);

private:
static
    void CnslWndNotifyFn(void* cbCtx, DWORD dwCbType, VOID* para);
    void CnslWndNotify(DWORD dwCbType, VOID* para);
    ConsoleEmbWnd* m_pcnslWnd;

private:
    HWND m_hWnd;
    HWND m_hWndParent;
//
// shell contex object
private:
    IWebBrowser2* m_pFrameWB;
    IInputObjectSite *m_pInputObjSite;    // Forcus change object
    // not used now
    DWORD m_dwViewMode;
    DWORD m_dwBandID;

private:
    BOOL m_fFocus;
    BOOL m_fSny2E;
    BOOL m_fSny2C;
    BOOL m_bPathSync;

};

OBJECT_ENTRY_AUTO(__uuidof(ShTerm), CShTerm)

